<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateAssetsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {

        Schema::create('asset_statuses', function(Blueprint $table){
            $table->increments('id');
            $table->string('name');
            $table->string('label')->nullable();
            $table->softDeletes();
            $table->timestamps();
        });
        Schema::create('asset_vendors', function(Blueprint $table){
            $table->increments('id');
            $table->string('name')->unique();
            $table->text("description")->nullable();
            $table->text("address")->nullable();
            $table->string("fax")->nullable();
            $table->string('email')->nullable();
            $table->string("contact_person_name")->nullable();
            $table->string("phone")->nullable();
            $table->softDeletes();
            $table->timestamps();
        });
        Schema::create('asset_affiliations', function(Blueprint $table){
            $table->increments('id');
            $table->string('name')->unique();
            $table->string("description")->nullable();
            $table->softDeletes();
            $table->timestamps();
        });
        Schema::create('asset_keepers', function(Blueprint $table){
            $table->increments('id');
            $table->string('name')->unique();
            $table->string('phone')->nullable();
            $table->string("description")->nullable();
            $table->softDeletes();
            $table->timestamps();
        });
        Schema::create('asset_locations', function(Blueprint $table){
            $table->increments('id');
            $table->string('name')->unique();
            $table->string("address")->nullable();
            $table->softDeletes();
            $table->timestamps();
        });
        Schema::create('asset_brands', function(Blueprint $table){
            $table->increments('id');
            $table->string('name')->unique();
            $table->softDeletes();
            $table->timestamps();
        });
        Schema::create('asset_categories', function(Blueprint $table){
            $table->increments('id');
            $table->string('name');
            $table->unsignedInteger("parent_id")->nullable();
            $table->softDeletes();
            $table->timestamps();
        });

        Schema::create('assets', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name');
            $table->string('product_model_number')->nullable();
            $table->unsignedBigInteger("category_id")->nullable();
            $table->unsignedBigInteger("sub_category_id")->nullable();
            $table->unsignedBigInteger("brand_id")->nullable();
            $table->string("sn")->nullable();
            $table->unsignedInteger("status_id")->default();
            $table->unsignedInteger('affiliation_id')->comment("归属");
            $table->unsignedInteger("keeper_id")->comment("保管人");
            $table->text('description')->nullable();

            $table->double("marking_price")->default(0.00);
            $table->double("bid_price")->default(0.00);
            $table->date('bid_date')->nullable();
            $table->unsignedBigInteger("vendor_id")->nullable();
            $table->unsignedBigInteger("location_id")->nullable();
            $table->softDeletes();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('assets');
        Schema::dropIfExists('asset_statuses');
        Schema::dropIfExists('asset_vendors');
        Schema::dropIfExists('asset_locations');
        Schema::dropIfExists('asset_keepers');
        Schema::dropIfExists('asset_affiliations');
        Schema::dropIfExists('asset_categories');
        Schema::dropIfExists('asset_brands');



    }
}
